package com.zxd.socket.service;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Objects;
import java.util.Scanner;

/**
 * ClassName:Service
 * Package:com.zxd.socket.service
 *
 * @Date:2023/10/6 17:19
 * @Author:zxde
 */
public class Clint {
    public static void main(String[] args) throws Exception {
        //创建客户端socket对象（需要连接的客户端地址）
        Socket socket = new Socket("localhost", 6666);
        //获得数据输出流对象
        OutputStream outputStream = socket.getOutputStream();
        //将字节输出流对象包装成DataOutputStream
        DataOutputStream dos = new DataOutputStream(outputStream);

        Scanner scanner = new Scanner(System.in);
        //循环发送信息
        while (true) {
            String msg = scanner.nextLine();
            if (Objects.equals(msg, "exit")) {
                break;
            }
            dos.writeUTF(msg);
        }
        scanner.close();
        dos.close();
        socket.close();
    }
}
